package com.frxuexi.visit

import com.blankj.utilcode.util.SPUtils
import com.frxuexi.lib_base.http.ApiService
import com.frxuexi.lib_base.http.Const
import com.frxuexi.lib_base.mvi.BaseViewModel
import com.frxuexi.lib_base.mvi.RequestType
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

@HiltViewModel
class VisitViewModel @Inject constructor(val apiService: ApiService):BaseViewModel<VisitIntent>(){
    override fun handleIntent(it: VisitIntent) {
        when(it){
            is VisitIntent.getVisits->httpRequest(apiService.getVisits())
            is VisitIntent.getVisitsByStatus->httpRequest(apiService.getVisitsByStatus(it.status))
            is VisitIntent.getVisitsByName->httpRequest(apiService.getVisitsByName(it.name))
            is VisitIntent.getVisitsByPurpose->httpRequest(apiService.getVisitsByPurpose(it.purpose))
            is VisitIntent.addVisit->httpRequest(apiService.addVisit(toBody(it.item)))
            is VisitIntent.upload->httpRequest(apiService.upload(toMultipartBody(it.name,it.path).parts,"visit",SPUtils.getInstance().getInt(Const.UID).toString()),RequestType.UPLOAD)
            is VisitIntent.getVisitById->httpRequest(apiService.getVisitById(it.id))
            is VisitIntent.approveVisit->httpRequest(apiService.approveVisit(it.id),RequestType.UPDATE)
            is VisitIntent.rejectVisit->httpRequest(apiService.rejectVisit(it.id),RequestType.UPDATE)
        }
    }
}